package com.service.websocket.config;

import com.service.websocket.Interceptor.WebSocketInterceptor;
import com.service.websocket.handler.MessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author xianggj
 * @description: websocket配置类
 * @date 2019/8/20 16:24
 */
@Configuration
@EnableWebMvc
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    protected MessageHandler messageHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(messageHandler, "kcsWs")
                .addInterceptors(new WebSocketInterceptor()).setAllowedOrigins("*");

        registry.addHandler(messageHandler, "kcsWs")
                .addInterceptors(new WebSocketInterceptor()).withSockJS();

    }


}
